﻿using Knlght.Data;
using Knlght.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Knight.Interface
{
    public interface IDefaultService
    {
        ActionResponse Add<TEntity>(TEntity model) where TEntity : TEntityBase, new();
        ActionResponse AddToList<TEntity>(List<TEntity> models ,string tableName, string connectionStr, string primaryKey, PrimaryKeyType type ) where TEntity : TEntityBase, new();
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        ActionResponse Update<TEntity>(TEntity model) where TEntity : TEntityBase, new();      
        /// <summary>
        /// 批量更新实体
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="request"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        ActionResponse UpdateToList<TEntity>(Expression<Func<TEntity, bool>> predicate, Expression<Func<TEntity, TEntity>> key) where TEntity : TEntityBase, new();      
        /// <summary>
        /// 删除实体，支持批量删除
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="request"></param>
        /// <returns></returns>
        ActionResponse Remove<TEntity>(Expression<Func<TEntity, bool>> predicate) where TEntity : TEntityBase, new();
        ItemResponse<TEntity> GetModel<TEntity>(Expression<Func<TEntity, bool>> predicate = null, Expression<Func<TEntity, TEntity>> selector = null) where TEntity : TEntityBase, new();        
        ItemResponse<TEntity> GetModel<TEntity>(object id) where TEntity : TEntityBase, new();      
        ListResponse<TEntity> GetList<TEntity>(QueryRequest<TEntity> request = null, Expression<Func<TEntity, TEntity>> selector = null) where TEntity : TEntityBase, new();
        /// <summary>
        /// 获取分页对象
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="request"></param>
        /// <returns></returns>
        PagingResponse<TEntity> Paging<TEntity>(PagingRequest<TEntity> request, Expression<Func<TEntity, TEntity>> selector = null) where TEntity : TEntityBase, new();
        /// <summary>
        /// 检查是否存在
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="predicate"></param>
        /// <returns></returns>
        ActionResponse IsExist<TEntity>(Expression<Func<TEntity, bool>> predicate) where TEntity : TEntityBase, new();
    }
}
